//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.serve;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chris.entity.register;
import com.chris.impl.registerImpl;
import com.chris.utils.DbConnection;
import com.chris.utils.JsonProcess;
import com.chris.utils.LogUtil;
import com.chris.utils.Page;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/searchJournalStock"})
public class searchJournalStock extends HttpServlet {
    private final registerImpl dao = new registerImpl();

    public searchJournalStock() {
    }

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();

        try {
            String journal_title = req.getParameter("journal_title");

            if (journal_title != null) {
                List<register> byTitle = this.dao.getByTitle(journal_title);
                String success = JSON.toJSONString(JsonProcess.respSuccess("成功", byTitle));
                writer.print(success);
            } else {
                List<register> all = dao.getAll();
                String success = JSON.toJSONString(JsonProcess.respSuccess("成功", all));
                writer.print(success);
            }
        } catch (Exception e) {
            JSONObject ans = JsonProcess.respError("参数错误");
            writer.println(ans);
            LogUtil.log("参数错误",e);
        }
        DbConnection.endServe();
    }

    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
    }
}
